package com.example.video.util;

import lombok.extern.slf4j.Slf4j;

import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;

/**
 * @ClassName FileToolUtil
 * @Description TODO
 * @Author Jason
 * @Date 2019/1/21 10:17
 * @Version 1.0
 **/
@Slf4j
public class FileToolUtil {
    /**
     * <p> inputStream to byte [] </p>
     *
     * @return byte[]
     * @Param [inputStream]
     * @author Jason
     **/
    public static byte[] inputStreamToByte(FileInputStream inputStream) throws IOException {
        byte[] byt = new byte[inputStream.available()];
        inputStream.read(byt);
        return byt;
    }

//    public static byte[] byteToInputStream(byte[] byt) throws IOException {
//        byte[] byt = new byte[inputStream.available()];
//        // int read = inputStream.read(byt);
//        return byt;
//    }

    public static void judeDirExists(File file) {
        if (file.exists()) {
            if (file.isDirectory()) {
                log.info("dir exists");
            } else {
                log.error("the same name file exists, can not create dir");
            }
        } else {
            log.info("dir not exists, create it ...");
            file.mkdirs();
        }
    }
}
